const {CODE_REQUIRED,CODE_ERROR}=require('../error/errorType')
const serviceSql=require('../service/service')

const verifyConvert=async(ctx,next)=>{
    let {code} = ctx.request.body
    if(!code){
        return ctx.app.emit('error',new Error(CODE_REQUIRED),ctx)
    }
    let [result]=await serviceSql.cdkeySelect(code)
    if(!result){
        return ctx.app.emit('error',new Error(CODE_ERROR),ctx)
    }
    ctx.code=code
    await next()
}

module.exports={
    verifyConvert
}